#include  <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "DirectoryTest.h"

using namespace SystemTool;

static void LogFile(std::string strMsg)
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/12.log";
    std::fstream os(strFilePath,std::ios::app | std::ios::out);
    os << strMsg << "\n";
    os.close();
}

void DirectoryTest()
{
    // Normal scene
    std::string strDirPath = "/Users/tangyingzhong/Desktop/Differ";

    if(!Directory::Create("C:\\Users\\tangyingzhong\\Desktop\\Differ2"))
    {
        LogFile("Failed to create dir");
    }
    Directory::Create(strDirPath,false);
    Directory::Create(strDirPath + "/Cmm");

    if(!Directory::IsExisted(strDirPath))
    {
        LogFile("Dir is not existed");
    }
    if(Directory::IsEmpty(strDirPath))
    {
        LogFile("Dir is empty");
    }

    // if(!Directory::Delete(strDirPath))
    // {
    //     LogFile("Failed to delete dir");
    // }

    Directory::Rename(strDirPath, "/Users/tangyingzhong/Desktop/Differ2");
    Directory::CopyTo("/Users/tangyingzhong/Desktop/Differ","/Users/tangyingzhong/Downloads");
    Directory::MoveTo("/Users/tangyingzhong/Desktop/Differ","/Users/tangyingzhong/Downloads");

    std::vector<std::string> vDirTable;
    Directory::GetAllSubDirs("/Users/tangyingzhong/Desktop/Differ2",vDirTable);

    std::vector<std::string> vFileTable;
    Directory::GetAllSubFiles("/Users/tangyingzhong/Desktop/Differ2",vFileTable);
    LogFile("Pause");

    size_t iSize = Directory::GetDirSize("/Users/tangyingzhong/Desktop/Differ2");
    std::string strMsg = std::string("Size=") + std::to_string(iSize);
    LogFile(strMsg);

    std::string strName = Directory::GetDirName("/Users/tangyingzhong/Desktop/Differ2");
    LogFile(strName);

    std::string strParentName = Directory::GetParentDirPath("/Users/tangyingzhong/Desktop/Differ2");
    LogFile(strParentName);

    unsigned long long iTotalSize = Directory::GetTotalSpace("/Users/tangyingzhong/Desktop/Differ2");
    unsigned long long iUsableSize = Directory::GetUsableSpace("/Users/tangyingzhong/Desktop/Differ2");
    unsigned long long iFreeSize = Directory::GetFreeSpace("/Users/tangyingzhong/Desktop/Differ2");
    LogFile("Pause");

    Directory::SetExcutable("/Users/tangyingzhong/Desktop/Differ2",false);
    Directory::SetWritable("/Users/tangyingzhong/Desktop/Differ2",false);

    Directory::SetExcutable("/Users/tangyingzhong/Desktop/Differ2");
    Directory::SetWritable("/Users/tangyingzhong/Desktop/Differ2");

    Directory::SetReadonly("/Users/tangyingzhong/Desktop/Differ2");
    LogFile("Pause");

    size_t iLastMT = Directory::GetLastModifyTime("/Users/tangyingzhong/Desktop/Differ2");
    LogFile("Pause");

    std::string strTempPath = Directory::GetTempPath();
    strTempPath = Directory::GetAppDataPath();
    strTempPath = Directory::GetDocumentPath();
    strTempPath = Directory::GetExcutablePath();
    strTempPath = Directory::GetCurWorkPath();
    
    std::string strPath = Directory::TrimPath("/Users/tangyingzhong/Desktop/Differ2/");
    strPath = Directory::StandardPath("\\Users\\tangyingzhong/Desktop\\Differ2");
    LogFile("Pause");
}
